/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectocallcentergrupo6;

import java.sql.*;

/**
 *
 * @author Eduardo
 */
public class Canales {
    String ID, HBO_HD, HBO_P, INF, FUTBOL;
    Conectar con = new Conectar();

    public Canales() {
    }
    
    
    
    public Canales Buscar(String id){
      Canales c = new Canales();
      try{
            PreparedStatement p = con.getConnection().prepareStatement("SELECT * FROM Canales"+
                    " WHERE SERVICIO_ID = ?");
            p.setString(1, id);
            ResultSet res = p.executeQuery();
            res.next();
            c.setID(res.getString("SERVICIO_ID"));
            c.setHBO_HD(res.getString("HBO_HD"));
            c.setHBO_P(res.getString("HBO_PLUS"));
            c.setINF(res.getString("INFANTIL"));
            c.setFUTBOL(res.getString("FUTBOL"));
            res.close();
        }catch(SQLException e){
            c=null;
        }
      return c;
  }
    public void modificar(String id, String HBOH, String HBOP, String INF, String FUTBOL){
      try{
          PreparedStatement p = con.getConnection().prepareStatement("UPDATE Canales " +
                  "set HBO_HD = ? , " +
                  "HBO_PLUS = ?, " +
                  "INFANTIL = ? , " +
                  "FUTBOL = ? " +
                  "WHERE SERVICIO_ID = ?");
          p.setString(1, HBOH);
          p.setString(2, HBOP);
          p.setString(3, INF);
          p.setString(4, FUTBOL);
          p.setString(5, id);
          p.execute();
          p.close();          
      }catch(SQLException e){
          System.out.println("ATENCION: " + e);
      }
      
  }
    public void eliminar(String id)
{
         try{
          PreparedStatement p = con.getConnection().prepareStatement("DELETE FROM canales WHERE ID_Canal = ?");
          p.setString(1,id);
          p.execute();
          p.close();
      }catch(SQLException e){
          System.out.println("ATENCION: "+e);
      }
      
  }
    public void agregarCanal(String ID){
       try {            
            String d = "0";
            PreparedStatement pstm = con.getConnection().prepareStatement("insert into " + 
                    "canales(SERVICIO_ID, ID_CANAL, HBO_HD, HBO_PLUS, INFANTIL, FUTBOL)" +
                    " values(?,?,?,?,?,?)");            
            pstm.setString(1, ID);
            pstm.setString(2, ID);
            pstm.setString(3, d);
            pstm.setString(4, d);
            pstm.setString(5, d);
            pstm.setString(6, d);
            pstm.execute();
            pstm.close();            
         }catch(SQLException e){
         System.out.println("ATENCION: "+e);
         }
     
   }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getHBO_HD() {
        return HBO_HD;
    }

    public void setHBO_HD(String HBO_HD) {
        this.HBO_HD = HBO_HD;
    }

    public String getHBO_P() {
        return HBO_P;
    }

    public void setHBO_P(String HBO_P) {
        this.HBO_P = HBO_P;
    }

    public String getINF() {
        return INF;
    }

    public void setINF(String INF) {
        this.INF = INF;
    }

    public String getFUTBOL() {
        return FUTBOL;
    }

    public void setFUTBOL(String FUTBOL) {
        this.FUTBOL = FUTBOL;
    }
  
}
